package com.ejuornal.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ejuornal.bean.Page;
import com.ejuornal.bean.UserExt;
import com.ejuornal.dao.impl.UserExtDaoImpl;
import com.ejuornal.service.UserExtService;
@Service("userExtService")
public class UserExtServiceImpl implements UserExtService {
	private  UserExtDaoImpl  userExtDaoImpl=null;
	
	public void add(UserExt userExt) {
		String  sql="insert into t_user_ext (userExtId,userId,realName,panName,sex,tel,company,position,degree,hobby,rank,score,headPic) values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
		
		userExtDaoImpl.add(sql, new Object[]{
				null,
				userExt.getUserId(),
				userExt.getRealName(),
				userExt.getPenName(),
				userExt.getSex(),
				userExt.getTel(),
				userExt.getCompany(),
				userExt.getPosition(),
				userExt.getDegree(),
				userExt.getHobby(),
				"1",
				0,
				userExt.getHeadPic()
				
		});
		System.out.println("serviceImpl  hobby="+userExt.getHobby());
	}

	public void delete(int... userExtIds) {
		String sql="delete from t_user_ext where userExtId = ?"; 
		userExtDaoImpl.batchDelete(sql, userExtIds);
	}

	public void update(UserExt userExt) {
		String  sql=" update t_user_ext set realName = ? , panName = ? , sex = ? , tel = ? , company = ? , position = ? , degree = ? , hobby = ? , rank = ? , score = ? , headPic = ? where userExtId = ? ";
	
		userExtDaoImpl.update(sql, new Object[]{				
				userExt.getRealName(),
				userExt.getPenName(),
				userExt.getSex(),
				userExt.getTel(),
				userExt.getCompany(),
				userExt.getPosition(),
				userExt.getDegree(),
				userExt.getHobby(),
				userExt.getRank(),
				userExt.getScore(),
				userExt.getHeadPic(),
				userExt.getUserExtId(),
		});
	}

	public Page<UserExt> findByProperty(int current_record, String url, Object property,
			Object value) {
		return userExtDaoImpl.findByProperty(current_record, url, property, value);
	}

	public UserExt findByUserId(int userId) {
		return userExtDaoImpl.getDetailByUserId(userId);
	}
	
	public boolean isUserExtExist(int userId) {
		return userExtDaoImpl.isUserExtExist(userId);
	}

	public UserExtDaoImpl getUserExtDaoImpl() {
		return userExtDaoImpl;
	}

	@Resource(name = "userExtDao")
	public void setUserExtDaoImpl(UserExtDaoImpl userExtDaoImpl) {
		this.userExtDaoImpl = userExtDaoImpl;
	}
}
